﻿<phone:PhoneApplicationPage
    x:Class="SC2TV.ClientPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModel="clr-namespace:SC2TV.ViewModel"
    xmlns:wpExtensions="clr-namespace:WPExtensions;assembly=WPExtensions"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.Resources>
        <viewModel:ClientViewModel x:Key="VM" />
        <DataTemplate x:Key="StreamTile">
            <Grid Margin="0,5,0,5" Background="#20FFFFFF">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Image Grid.Row="1" Source="{Binding Picture}"/>
                <TextBlock Grid.Row="0" Text="{Binding Title}" TextWrapping="Wrap"/>
                <TextBlock Grid.Row="2" Text="{Binding User}"/>
                <TextBlock Grid.Row="3" Text="{Binding Rating}"/>
                <TextBlock Grid.Row="4" Text="{Binding Description}" TextWrapping="Wrap"/>
            </Grid>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    <phone:PhoneApplicationPage.DataContext>
        <Binding Source="{StaticResource VM}"/>
    </phone:PhoneApplicationPage.DataContext>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <wpExtensions:AdvancedApplicationBar>
            <wpExtensions:AdvancedApplicationBarIconButton Text="{Binding Text.Refresh}" IconUri="/Assets/Icons/appbar.refresh.png" Command="{Binding Refresh}"/>
            <wpExtensions:AdvancedApplicationBarMenuItem Text="{Binding Text.ChangeUser}" Click="LogoutClick"/>
            <wpExtensions:AdvancedApplicationBarMenuItem Text="{Binding Text.About}" Click="AboutClick"/>
        </wpExtensions:AdvancedApplicationBar>
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="{Binding Text.ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>
        </StackPanel>

        <phone:Pivot Grid.Row="1" Margin="12,0,12,0">
            <phone:PivotItem Header="{Binding Text.Favorites}">
                <phone:LongListSelector ItemsSource="{Binding Favorites}" ItemTemplate="{StaticResource StreamTile}" SelectionChanged="StreamSelected" />
            </phone:PivotItem>
            <phone:PivotItem Header="{Binding Text.FanStreams}">
                <phone:LongListSelector ItemsSource="{Binding FanStreams}" ItemTemplate="{StaticResource StreamTile}" SelectionChanged="StreamSelected" />
            </phone:PivotItem>
            <phone:PivotItem Header="{Binding Text.RealStreams}">
                <phone:LongListSelector ItemsSource="{Binding RealStreams}" ItemTemplate="{StaticResource StreamTile}" SelectionChanged="StreamSelected" />
            </phone:PivotItem>
            <phone:PivotItem Header="{Binding Text.GOSU}">
                <phone:LongListSelector ItemsSource="{Binding GOSU}" ItemTemplate="{StaticResource StreamTile}" SelectionChanged="StreamSelected" />
            </phone:PivotItem>
            <phone:PivotItem Header="{Binding Text.PrivateMessages}">
                <phone:LongListSelector ItemsSource="{Binding PrivateMessages}" SelectionChanged="PrivateMessageClick" >
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,5,0,5" Background="#20FFFFFF">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock Text="{Binding Participants}"/>
                                <TextBlock Grid.Row="1" Text="{Binding Title}"/>
                                <TextBlock Grid.Row="2" HorizontalAlignment="Right" Text="{Binding Date}"/>
                            </Grid>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
            </phone:PivotItem>
        </phone:Pivot>
    </Grid>

</phone:PhoneApplicationPage>